import apiClient from '@/api/apiClient';
import { NoticeSearchData, NoticeType } from '@/pages/setting/notice/type';

import { ListData } from '#/entity';

// CRUD
export enum Api {
  List = '/management/notices',
  CUD = '/management/notice',
}

// /notices
const list = (searchData: NoticeSearchData) =>
  apiClient.get<ListData<NoticeType>>({ url: Api.List, params: searchData });

// /notice
const create = (data: NoticeType) =>
  apiClient.post<number>({
    url: Api.CUD,
    data,
  });

const deleteBatch = (data: { ids: string }) =>
  apiClient.delete<number>({
    url: `${Api.CUD}`,
    params: data,
  });

// /notice/4
const update = (id: number, data: Partial<NoticeType>) =>
  apiClient.put<number>({
    // 添加返回类型
    url: `${Api.CUD}/${id}`,
    data,
  });

export default {
  list,
  create,
  deleteBatch,
  update,
};
